/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import br.com.dao.HospedeDAO;
import br.com.modelo.HospedeBean;
import javax.servlet.RequestDispatcher;

/**
 *
 * @author Felipe
 */
public class ClienteController extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
    }
    
  

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
            String acao = request.getParameter("logica");
            HospedeDAO hd =new  HospedeDAO();
      
        if(acao.equals("cadastrar")){
          
            HospedeBean hb = new HospedeBean();
            hb.setCd_doc(Integer.parseInt(request.getParameter("txtcpf").trim()));
            hb.setTp_doc(request.getParameter("txttipodoc"));
            hb.setNome(request.getParameter("txtnome"));
            hb.setEndereco(request.getParameter("txtend"));
            hb.setCidade(request.getParameter("txtcid"));
            hb.setEstado(request.getParameter("txtest"));
            hb.setSexo(request.getParameter("bradio"));
            hb.setProfissao(request.getParameter("txtprof"));
            hb.setData_nascimento(request.getParameter("txtnasc"));
            hb.setEstado_civil(request.getParameter("estcivil"));
            
           hd.adiciona(hb);
            RequestDispatcher rd = request
					.getRequestDispatcher("sucesso.jsp");
					rd.forward(request,response);
            
        
        }else if(acao.equals("excluir")){
            HospedeBean hb = new HospedeBean();
             hb.setCd_doc(Integer.parseInt(request.getParameter("txtcpf").trim()));
             hd.remove(hb);
              RequestDispatcher rd = request
					.getRequestDispatcher("sucesso.jsp");
					rd.forward(request,response);
        }else if(acao.equals("alterar")){
            HospedeBean hb = new HospedeBean();
            hb.setCd_doc(Integer.parseInt(request.getParameter("txtcpf").trim()));
            hb.setTp_doc(request.getParameter("txttipodoc"));
            hb.setNome(request.getParameter("txtnome"));
            hb.setEndereco(request.getParameter("txtend"));
            hb.setCidade(request.getParameter("txtcid"));
            hb.setEstado(request.getParameter("txtest"));
            hb.setSexo(request.getParameter("bradio"));
            hb.setProfissao(request.getParameter("txtprof"));
            hb.setData_nascimento(request.getParameter("txtnasc"));
            hb.setEstado_civil(request.getParameter("estcivil"));
            hd.altera(hb);
             
              RequestDispatcher rd = request
					.getRequestDispatcher("sucesso.jsp");
					rd.forward(request,response);
    }
    }
    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
